<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <script>
    //将json格式字符串转为json
    var str = '{"name" : "zs", "age" : 20}';
    var result = JSON.parse(str);
    console.log(result.name,result.age);// zs 20

    // var str1 = "{'name' : 'ls', 'age' : 22}";
    // var result1 = JSON.parse(str1);
    // console.log(result1);//Uncaught SyntaxError: Unexpected token ' in JSON at position 1 at JSON.parse (<anonymous>)
    
    var arr = '["aaa", "bbb", "ccc"]';
    var result2 = JSON.parse(arr);
    console.log(result2);// ["aaa", "bbb", "ccc"]

    var arrjson = '[{"name":"zs", "age":20 },{"name":"ls", "age":25},{"name":"ww", "age":22}]';
    var result3 = JSON.parse(arrjson);
    console.log(result3);// [{name:"zs", age:20 },{name:"ls", age:25},{name:"ww", "age":22}]
  </script>
</body>
</html>